﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Sheep_Breeding.ErrorCode;
using Sheep_Breeding.Write.Api.DTOSheep;
using Sheep_Breeding.Write.Api.OperationServices.IServices;

namespace Sheep_Breeding.Write.Api.Controllers
{
    /// <summary>
    /// 羊场管理控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SheepfarmController : ControllerBase
    {
        private readonly ILogger<SheepfarmController> logger;
        private readonly ISheepfarmServices sheepfarmServices;

        public SheepfarmController(ILogger<SheepfarmController> logger,ISheepfarmServices sheepfarmServices)
        {
            this.logger = logger;
            this.sheepfarmServices = sheepfarmServices;
        }

        /// <summary>
        /// 新增羊场信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> CreateSheepfarm(CreateSheepfarmDto dto)
        {
            try
            {
                return await sheepfarmServices.CreateSheepfarm(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }

        /// <summary>
        /// 修改羊场信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult> UpdateSheepfarm(UpdateSheepfarm dto)
        {
            try
            {
                return await sheepfarmServices.UpdateSheepfarm(dto);
            }
            catch (Exception ex)
            {

                logger.LogError("=>" + ex.Message);
                throw ex;
            }
        }
    }
}
